/*****************************************************
PROJECT: BRIDGE C2 SCRAP
JOB:
REQUESTOR:Rachel Gold
JIRA #:
ANALYST: MLT
DATE: 9/15/2022
   rerun 12/14/2023 on deduplicated denominator;
VERSION: 
LAST UPDATED: 
PEER REVIEWER: 

PROJECT DESCRIPTION: Use ASCEND approach to compare CRC, BC and 
BC cancer prevention services in patients with
	No SDH Screening
	Documented Need
	Documented No Need
Stratified by SDH need: Food, Housing, Transportation
STUDY PERIOD: 7/1/2016-2/29/2020		

DETAILS (this file): 
Table 1 for BC
    Patients
	Race and ethnicity
	Preferred language
	Age at Index encounter (median, range)
	Age Group at Index
	Payer at Index
	FPL 
	Visit per Year
	Years of Observation
	BC status at Index
	Last BC screen type prior to Index
	Years of Observation after first Due date
	Ever due for screening during observation	
Columns Food Insecurity: Need/ No Need/ Not documented
Columns Housing Insecurity: Need/ No Need/ Not documented
Columns Transportation Insecurity: Need/ No Need/ Not documented
		

INPUT DATA:
SCRAP.BC_patient_covariates;
SCRAP.BC_status_at_index;

OUTPUT DATA:


RELATED FILE: 


SECTIONS:

****************************************************/
options compress=yes reuse=yes;
libname SCRAP "e:\\sasroot\BRIDGE C2\SCRAP\";
libname final "e:\\sasroot\BRIDGE C2\SCRAP\BC_table_1";
libname RD odbc noprompt="dsn=research_dev;Trusted_Connection=yes" bulkload=yes;
/****************************************************/

data analysis0;
set SCRAP.BC_patient_covariates;
rename sdh_transportation=sdh_trans;
run;

proc sort data=analysis0 out=analysis;
by advance_patid;
run;

data single multiple;
set analysis;
by advance_patid;
if first.advance_patid and last.advance_patid then output single;
if ^(first.advance_patid and last.advance_patid) then output multiple;
run;

proc sort nodup data=multiple out=multiple2 dupout=dups;
by advance_patid;
run;

data single2 mult3;
set multiple2;
by advance_patid;
if first.advance_patid and last.advance_patid then output single2;
if ^(first.advance_patid and last.advance_patid) then output mult3;
run;

data analysis;
set single single2;
run;


data status_index;
set SCRAP.BC_status_at_index;
rename sdh_transportation=sdh_trans;
run;

/*Headers setting dynamic variables*/
%let cancer=BC;

/*************************************************
STEP 1: 
Uncomment lines 119-121
Run full progarm to generate food_insecurity numbers
**************************************************/
/*%let sdh=SDH_food;*/
/*%let temp=final.temp_table1_food;*/
/*%let out_chi=final.temp_table1_chisq_food;*/
/*************************************************

STEP 2: 
comment out lines 119-121, Uncomment lines 128-130
Run full progarm to generate housing_insecurity numbers
**************************************************/
/*%let sdh=SDH_housing;*/
/*%let temp=final.temp_table1_housing;*/
/*%let out_chi=final.temp_table1_chisq_housing;*/

/*************************************************
STEP 3: 
comment out lines 128-130, Uncomment 137-139
Run full progarm to generate housing_insecurity numbers
**************************************************/
/*%let sdh=SDH_trans;*/
/*%let temp=final.temp_table1_transportation;*/
/*%let out_chi=final.temp_table1_chisq_transportation;*/



/*************************************************
STEP 4: 
Uncomment and run lines 149-164
export  to excel
**************************************************/

data SCRAP.BC_Table1;
merge final.temp_table1_food final.temp_table1_housing final.temp_table1_transportation;
by row variable ;
run;



/*   Patients*/

proc freq data=analysis;
tables &sdh;
ods output onewayfreqs=sdh_cat;
run;

data Row1 (Keep=Row Variable total need_&sdh  
noneed_&sdh  nodoc_&sdh );
set sdh_cat;
row=1;
length Variable $25;
retain Variable total need_&sdh   
noneed_&sdh nodoc_&sdh;
variable='Patients_N';
total=.;

if &sdh='1_Positive Screen' then 
	need_&sdh=Frequency;
if &sdh='2_Negative Screen' then 
	noneed_&sdh=Frequency;
if &sdh='3_Never Screened' then do;
	total=CumFrequency;
	nodoc_&sdh=Frequency;
    output;
end;
run;

/*	sex*/
		
proc freq data=analysis;
tables sex_r*&sdh/nocol ;
ods output crosstabfreqs=sex_r ;
run;
data Row3 (Keep=Row Variable total need_&sdh  
noneed_&sdh  nodoc_&sdh );
set sex_r;
where _type_ in('10','11') and sex_r='F';
row=3;
retain Variable total need_&sdh   
noneed_&sdh nodoc_&sdh;

length Variable $25;
Variable='Female, %';
if &sdh='1_Positive Screen' then 
		need_&sdh=round(rowpercent,0.1);
if &sdh='2_Negative Screen' then 
		noneed_&sdh=round(rowpercent,0.1);
if &sdh='3_Never Screened' then 
		nodoc_&sdh=round(rowpercent,0.1);
if _type_='10' then do;
		total=round(percent,0.1);
		output;
end;
run;
data &cancer;
set row1 row3;
run;
/*data chisq_sex&sdh;*/
/*set chisq_sex&sdh;*/
/*where statistic='Chi-Square';*/
/*length characteristic $15;*/
/*characteristic='Sex';*/
/*run;*/
proc freq data=analysis;
tables race_ethnic*&sdh/nocol chisq;
ods output crosstabfreqs=race_ethnic chisq=chisq_race&sdh;
run;
data Row4_8 (Keep=Row Variable total need_&sdh  
noneed_&sdh  nodoc_&sdh );
set race_ethnic;
where _type_ in('10','11');
retain total need_&sdh noneed_&sdh nodoc_&sdh ;
total=.;
length Variable $25;
if race_ethnic='Hispanic' then do;
	Variable='Hispanic, %';
	Row=4;
	if &sdh='1_Positive Screen' then 
		need_&sdh=round(rowpercent,0.1);
	if &sdh='2_Negative Screen' then 
		noneed_&sdh=round(rowpercent,0.1);
	if &sdh='3_Never Screened' then 
		nodoc_&sdh=round(rowpercent,0.1);
	if _type_='10' then do;
		total=round(percent,0.1);
			output;
	end;
end;
if race_ethnic='Nonhispanic Black' then do;
	Variable='Non-Hispanic Black, %';
	Row=5;
	if &sdh='1_Positive Screen' then 
		need_&sdh=round(rowpercent,0.1);
	if &sdh='2_Negative Screen' then 
		noneed_&sdh=round(rowpercent,0.1);
	if &sdh='3_Never Screened' then 
		nodoc_&sdh=round(rowpercent,0.1);
	if _type_='10' then do;
		total=round(percent,0.1);
			output;
	end;	
end;
if race_ethnic='Nonhispanic White' then do;
	Variable='Non-Hispanic White, %';
	Row=6;
	if &sdh='1_Positive Screen' then 
		need_&sdh=round(rowpercent,0.1);
	if &sdh='2_Negative Screen' then 
		noneed_&sdh=round(rowpercent,0.1);
	if &sdh='3_Never Screened' then 
		nodoc_&sdh=round(rowpercent,0.1);
	if _type_='10' then do;
		total=round(percent,0.1);
			output;
	end;	
end;
if race_ethnic='Nonhispanic Other' then do;
	Variable='Non-Hispanic other, %';
	Row=7;
	if &sdh='1_Positive Screen' then 
		need_&sdh=round(rowpercent,0.1);
	if &sdh='2_Negative Screen' then 
		noneed_&sdh=round(rowpercent,0.1);
	if &sdh='3_Never Screened' then 
		nodoc_&sdh=round(rowpercent,0.1);
	if _type_='10' then do;
		total=round(percent,0.1);
			output;
	end;
end;
if race_ethnic='Unknown' then do;
	Variable='No data, %';
	Row=8;
	if &sdh='1_Positive Screen' then 
		need_&sdh=round(rowpercent,0.1);
	if &sdh='2_Negative Screen' then 
		noneed_&sdh=round(rowpercent,0.1);
	if &sdh='3_Never Screened' then 
		nodoc_&sdh=round(rowpercent,0.1);
	if _type_='10' then do;
		total=round(percent,0.1);
			output;
		end;
end;
run;
proc sort data=row4_8;
by row;
run;
data &cancer;
set &cancer row4_8;
run;
data chisq_race&sdh;
set chisq_race&sdh;
where statistic='Chi-Square';
length characteristic $15;
characteristic='Race-ethnic';
run;

/*	Preferred language*/

proc freq data=analysis;
tables english*&sdh/nocol chisq ;
ods output crosstabfreqs=language chisq=chisq_language&sdh;
run;

data Row9_10 (Keep=Row Variable total need_&sdh  
noneed_&sdh  nodoc_&sdh );
set language;
where _type_ in('10','11');
retain row total need_&sdh noneed_&sdh nodoc_&sdh ;
length Variable $25;
total=.;
if english=1 then do;
	Variable='English, %';
	Row=9;
	if &sdh='1_Positive Screen' then 
		need_&sdh=round(rowpercent,0.1);
	if &sdh='2_Negative Screen' then 
		noneed_&sdh=round(rowpercent,0.1);
	if &sdh='3_Never Screened' then 
		nodoc_&sdh=round(rowpercent,0.1);
	if _type_='10' then do;
		total=round(percent,0.1);
			output;
	end;
end;
if english=0 then do;
	Variable='Non-English, %';
	Row=10;
	if &sdh='1_Positive Screen' then 
		need_&sdh=round(rowpercent,0.1);
	if &sdh='2_Negative Screen' then 
		noneed_&sdh=round(rowpercent,0.1);
	if &sdh='3_Never Screened' then 
		nodoc_&sdh=round(rowpercent,0.1);
	if _type_='10' then do;
		total=round(percent,0.1);
			output;
	end;
end;
run;
data &cancer;
set &cancer row9_10;
run;
data chisq_language&sdh;
set chisq_language&sdh;
where statistic='Chi-Square';
length characteristic $15;
characteristic='Language';
run;
proc sort data=&cancer; by row;run;

/*	Age at Index encounter (median, range)*/

proc means median min max data=analysis;
var age_at_index_visit;
ods output summary=age1;
run;
proc means median min max data=analysis;
class &sdh;
var age_at_index_visit;
ods output summary=age2;
run;

data Row11A (Keep=Row variable total_txt);
set age1;
retain row need_&sdh.txt noneed_&sdh.txt nodoc_&sdh.txt ;
length Variable result $25;
median=put(age_at_index_visit_median, best2.);
min=put(age_at_index_visit_min, best2.);
max=put(age_at_index_visit_max, best2.);
comma=", ";
open=" (";
close=")";
total_txt=cat(median,open, min, comma, max, close);
Variable='Total';
	Row=11;
run;
data Row11B (Keep=Row variable need_&sdh.txt noneed_&sdh.txt nodoc_&sdh.txt);
set age2;
retain row need_&sdh.txt noneed_&sdh.txt nodoc_&sdh.txt ;
length Variable result $25;
median=put(age_at_index_visit_median, best2.);
min=put(age_at_index_visit_min, best2.);
max=put(age_at_index_visit_max, best2.);
comma=", ";
open=" (";
close=")";

result=cat(median,open, min, comma, max, close);
Variable='Age Median(Range)';
	Row=11;
	if &sdh='1_Positive Screen' then
		need_&sdh.txt=result;
	if &sdh='2_Negative Screen' then 
		noneed_&sdh.txt=result;
	if &sdh='3_Never Screened' then do;
		nodoc_&sdh.txt=result;
		output;
	end;
run;
data row11;
merge row11A row11b;
by row;
run;
data &cancer;
set &cancer row11;
run;

/*	Age Group at Index*/

proc freq data=analysis;
tables age_cat*&sdh/nocol chisq;
ods output crosstabfreqs=age_cat chisq=chisq_age&sdh;
run;


data Row12_13 (Keep=Row Variable total need_&sdh  
noneed_&sdh  nodoc_&sdh );;
set age_cat;
where _type_ in('10','11');
retain row total need_&sdh noneed_&sdh nodoc_&sdh ;
length Variable $25;
if age_cat='23-39' then do;
	Variable='23-39';
	Row=12;
	if &sdh='1_Positive Screen' then 
		need_&sdh=round(rowpercent,0.1);
	if &sdh='2_Negative Screen' then 
		noneed_&sdh=round(rowpercent,0.1);
	if &sdh='3_Never Screened' then 
		nodoc_&sdh=round(rowpercent,0.1);
	if _type_='10' then do;
		total=round(percent,0.1);
			output;
	end;
end;
if age_cat='40-49' then do;
	Variable='40-49';
	Row=12;
	if &sdh='1_Positive Screen' then 
		need_&sdh=round(rowpercent,0.1);
	if &sdh='2_Negative Screen' then 
		noneed_&sdh=round(rowpercent,0.1);
	if &sdh='3_Never Screened' then 
		nodoc_&sdh=round(rowpercent,0.1);
	if _type_='10' then do;
		total=round(percent,0.1);
			output;
	end;
end;
if age_cat='50-64' then do;
	Variable='50-64';
	Row=12;
	if &sdh='1_Positive Screen' then 
		need_&sdh=round(rowpercent,0.1);
	if &sdh='2_Negative Screen' then 
		noneed_&sdh=round(rowpercent,0.1);
	if &sdh='3_Never Screened' then 
		nodoc_&sdh=round(rowpercent,0.1);
	if _type_='10' then do;
		total=round(percent,0.1);
			output;
	end;
end;
if age_cat='65-73' then do;
	Variable='65-73';
	Row=13;
	if &sdh='1_Positive Screen' then 
		need_&sdh=round(rowpercent,0.1);
	if &sdh='2_Negative Screen' then 
		noneed_&sdh=round(rowpercent,0.1);
	if &sdh='3_Never Screened' then 
		nodoc_&sdh=round(rowpercent,0.1);
	if _type_='10' then do;
		total=round(percent,0.1);
			output;
	end;
end;
run;
data &cancer;
set &cancer row12_13;
run;
data chisq_age&sdh;
set chisq_age&sdh;
where statistic='Chi-Square';
length characteristic $15;
characteristic='Age_cat';
run;

/*	Payer at Index*/

proc freq data=analysis;
tables payor_type_research*&sdh/nocol chisq;
ods output crosstabfreqs=payor chisq=chisq_payer&sdh;
run;


data Row14_18 (Keep=Row Variable total need_&sdh  
noneed_&sdh  nodoc_&sdh );;
set payor;
where _type_ in('10','11');
retain row total need_&sdh noneed_&sdh nodoc_&sdh ;
length Variable $25;
if payor_type_research='Medicaid' then do;
	Variable='Medicaid';
	Row=14;
	if &sdh='1_Positive Screen' then 
		need_&sdh=round(rowpercent,0.1);
	if &sdh='2_Negative Screen' then 
		noneed_&sdh=round(rowpercent,0.1);
	if &sdh='3_Never Screened' then 
		nodoc_&sdh=round(rowpercent,0.1);
	if _type_='10' then do;
		total=round(percent,0.1);
			output;
	end;
end;
if payor_type_research='Medicare' then do;
	Variable='Medicare';
	Row=15;
	if &sdh='1_Positive Screen' then 
		need_&sdh=round(rowpercent,0.1);
	if &sdh='2_Negative Screen' then 
		noneed_&sdh=round(rowpercent,0.1);
	if &sdh='3_Never Screened' then 
		nodoc_&sdh=round(rowpercent,0.1);
	if _type_='10' then do;
		total=round(percent,0.1);
			output;
	end;
end;
if payor_type_research='Other Public' then do;
	Variable='Other public';
	Row=16;
	if &sdh='1_Positive Screen' then 
		need_&sdh=round(rowpercent,0.1);
	if &sdh='2_Negative Screen' then 
		noneed_&sdh=round(rowpercent,0.1);
	if &sdh='3_Never Screened' then 
		nodoc_&sdh=round(rowpercent,0.1);
	if _type_='10' then do;
		total=round(percent,0.1);
			output;
	end;
end;
if payor_type_research='Private' then do;
	Variable='Private';
	Row=17;
	if &sdh='1_Positive Screen' then 
		need_&sdh=round(rowpercent,0.1);
	if &sdh='2_Negative Screen' then 
		noneed_&sdh=round(rowpercent,0.1);
	if &sdh='3_Never Screened' then 
		nodoc_&sdh=round(rowpercent,0.1);
	if _type_='10' then do;
		total=round(percent,0.1);
			output;
	end;
end;
if payor_type_research='Uninsured' then do;
	Variable='Uninsured';
	Row=18;
	if &sdh='1_Positive Screen' then 
		need_&sdh=round(rowpercent,0.1);
	if &sdh='2_Negative Screen' then 
		noneed_&sdh=round(rowpercent,0.1);
	if &sdh='3_Never Screened' then 
		nodoc_&sdh=round(rowpercent,0.1);
	if _type_='10' then do;
		total=round(percent,0.1);
			output;
	end;
end;
run;
data &cancer;
set &cancer row14_18;
run;

data chisq_payer&sdh;
set chisq_payer&sdh;
where statistic='Chi-Square';
length characteristic $15;
characteristic='Payer';
run;

/*	FPL */

proc freq data=analysis;
tables FPL_cat*&sdh/nocol chisq ;
ods output crosstabfreqs=fpl chisq=chisq_FPL&SDH;
run;


data Row19_22 (Keep=Row Variable total need_&sdh  
noneed_&sdh  nodoc_&sdh );;
set fpl;
where _type_ in('10','11');
retain row total need_&sdh noneed_&sdh nodoc_&sdh ;
length Variable $25;
if FPL_cat='<=100' then do;
	Variable='<=100';
	Row=19;
	if &sdh='1_Positive Screen' then 
		need_&sdh=round(rowpercent,0.1);
	if &sdh='2_Negative Screen' then 
		noneed_&sdh=round(rowpercent,0.1);
	if &sdh='3_Never Screened' then 
		nodoc_&sdh=round(rowpercent,0.1);
	if _type_='10' then do;
		total=round(percent,0.1);
			output;
	end;
end;
if FPL_cat='<=200' then do;
	Variable='>100 - 200';
	Row=20;
	if &sdh='1_Positive Screen' then 
		need_&sdh=round(rowpercent,0.1);
	if &sdh='2_Negative Screen' then 
		noneed_&sdh=round(rowpercent,0.1);
	if &sdh='3_Never Screened' then 
		nodoc_&sdh=round(rowpercent,0.1);
	if _type_='10' then do;
		total=round(percent,0.1);
			output;
	end;
end;
if FPL_cat='>200' then do;
	Variable='>200';
	Row=21;
	if &sdh='1_Positive Screen' then 
		need_&sdh=round(rowpercent,0.1);
	if &sdh='2_Negative Screen' then 
		noneed_&sdh=round(rowpercent,0.1);
	if &sdh='3_Never Screened' then 
		nodoc_&sdh=round(rowpercent,0.1);
	if _type_='10' then do;
		total=round(percent,0.1);
			output;
	end;
end;
if FPL_cat='No data' then do;
	Variable='No data';
	Row=22;
	if &sdh='1_Positive Screen' then 
		need_&sdh=round(rowpercent,0.1);
	if &sdh='2_Negative Screen' then 
		noneed_&sdh=round(rowpercent,0.1);
	if &sdh='3_Never Screened' then 
		nodoc_&sdh=round(rowpercent,0.1);
	if _type_='10' then do;
		total=round(percent,0.1);
			output;
	end;
end;

run;
data &cancer;
set &cancer row19_22;
run;
data chisq_FPL&sdh;
set chisq_FPL&sdh;
where statistic='Chi-Square';
length characteristic $15;
characteristic='FPL';
run;
/*	Visit per Year*/


proc freq data=analysis;
tables visit_cat*&sdh/nocol chisq;
ods output crosstabfreqs=visits chisq=chisq_visits&sdh;
run;


data Row23_26 (Keep=Row Variable total need_&sdh  
noneed_&sdh  nodoc_&sdh );;
set visits;
where _type_ in ('10','11');
retain row total need_&sdh noneed_&sdh nodoc_&sdh ;
length Variable $25;
if visit_cat='1-2' then do;
	Variable='1-2 visits';
	Row=23;
	if &sdh='1_Positive Screen' then 
		need_&sdh=round(rowpercent,0.1);
	if &sdh='2_Negative Screen' then 
		noneed_&sdh=round(rowpercent,0.1);
	if &sdh='3_Never Screened' then 
		nodoc_&sdh=round(rowpercent,0.1);
	if _type_='10' then do;
		total=round(percent,0.1);
			output;
	end;
end;
if visit_cat='3-4' then do;
	Variable='3-4 visits';
	Row=24;
	if &sdh='1_Positive Screen' then 
		need_&sdh=round(rowpercent,0.1);
	if &sdh='2_Negative Screen' then 
		noneed_&sdh=round(rowpercent,0.1);
	if &sdh='3_Never Screened' then 
		nodoc_&sdh=round(rowpercent,0.1);
	if _type_='10' then do;
		total=round(percent,0.1);
			output;
	end;
end;
if visit_cat='5-6' then do;
	Variable='5-6 visits';
	Row=25;
	if &sdh='1_Positive Screen' then 
		need_&sdh=round(rowpercent,0.1);
	if &sdh='2_Negative Screen' then 
		noneed_&sdh=round(rowpercent,0.1);
	if &sdh='3_Never Screened' then 
		nodoc_&sdh=round(rowpercent,0.1);
	if _type_='10' then do;
		total=round(percent,0.1);
			output;
	end;
end;
if visit_cat='7+' then do;
	Variable='7+ visits';
	Row=26;
	if &sdh='1_Positive Screen' then 
		need_&sdh=round(rowpercent,0.1);
	if &sdh='2_Negative Screen' then 
		noneed_&sdh=round(rowpercent,0.1);
	if &sdh='3_Never Screened' then 
		nodoc_&sdh=round(rowpercent,0.1);
	if _type_='10' then do;
		total=round(percent,0.1);
			output;
	end;
end;
run;
data &cancer;
set &cancer row23_26;
run;
data chisq_Visits&sdh;
set chisq_Visits&sdh;
where statistic='Chi-Square';
length characteristic $15;
characteristic='Visits per Year';
run;


/*	Years of Observation*/

proc freq data=analysis;
tables obs_cat*&sdh/nocol chisq;
ods output crosstabfreqs=obs chisq=chisq_obs&sdh;
run;


data Row27_28 (Keep=Row total Variable need_&sdh  
noneed_&sdh  nodoc_&sdh );;
set obs;
where _type_ in('10','11');
retain row total need_&sdh noneed_&sdh nodoc_&sdh ;
length Variable $25;
if obs_cat='<2' then do;
	Variable='<2 years';
	Row=27;
	if &sdh='1_Positive Screen' then 
		need_&sdh=round(rowpercent,0.1);
	if &sdh='2_Negative Screen' then 
		noneed_&sdh=round(rowpercent,0.1);
	if &sdh='3_Never Screened' then 
		nodoc_&sdh=round(rowpercent,0.1);
	if _type_='10' then do;
		total=round(percent,0.1);
			output;
	end;
end;
if obs_cat='2-3.6' then do;
	Variable='2-3.6 years';
	Row=28;
	if &sdh='1_Positive Screen' then 
		need_&sdh=round(rowpercent,0.1);
	if &sdh='2_Negative Screen' then 
		noneed_&sdh=round(rowpercent,0.1);
	if &sdh='3_Never Screened' then 
		nodoc_&sdh=round(rowpercent,0.1);
	if _type_='10' then do;
		total=round(percent,0.1);
			output;
	end;
end;
run;
data &cancer;
set &cancer row27_28;
run;

data chisq_obs&sdh;
set chisq_obs&sdh;
where statistic='Chi-Square';
length characteristic $15;
characteristic='Years of observation';
run;


/*	BC status at Index*/
proc freq data=status_index;
tables status_at_index*&sdh/nocol chisq;
ods output crosstabfreqs=status chisq=chisqstatus&sdh;
run;

data Row29_30 (Keep=Row total Variable need_&sdh  
noneed_&sdh  nodoc_&sdh );;
set status;
where _type_ in('10','11');
retain row total need_&sdh noneed_&sdh nodoc_&sdh ;
length Variable $25;
if status_at_index='Due' then do;
	Variable='Due';
	Row=29;
	if &sdh='1_Positive Screen' then 
		need_&sdh=round(rowpercent,0.1);
	if &sdh='2_Negative Screen' then 
		noneed_&sdh=round(rowpercent,0.1);
	if &sdh='3_Never Screened' then 
		nodoc_&sdh=round(rowpercent,0.1);
	if _type_='10' then do;
		total=round(percent,0.1);
			output;
	end;
end;
if status_at_index='Screened Prior' then do;
	Variable='Screened prior to Index';
	Row=30;
	if &sdh='1_Positive Screen' then 
		need_&sdh=round(rowpercent,0.1);
	if &sdh='2_Negative Screen' then 
		noneed_&sdh=round(rowpercent,0.1);
	if &sdh='3_Never Screened' then 
		nodoc_&sdh=round(rowpercent,0.1);
	if _type_='10' then do;
		total=round(percent,0.1);
			output;
	end;
end;

run;
data &cancer;
set &cancer row29_30;
run;
data chisq_status&sdh;
set chisqstatus&sdh;
where statistic='Chi-Square';
length characteristic $15;
characteristic='Status at Index';
run;

/*	Ever due for screening during observation	*/
proc freq data=status_index;
tables ever_due*&sdh/nocol chisq;
ods output crosstabfreqs=ever_due chisq=chisq_neverdue&sdh;
run;
data Row33_34 (Keep=Row total Variable need_&sdh  
noneed_&sdh  nodoc_&sdh );;
set ever_due;
where _type_ in('10','11');
retain row total  need_&sdh noneed_&sdh nodoc_&sdh ;
length Variable $25;
if ever_due=0 then do;
	Variable='Not due during observation';
	Row=33;
	if &sdh='1_Positive Screen' then 
		need_&sdh=round(rowpercent,0.1);
	if &sdh='2_Negative Screen' then 
		noneed_&sdh=round(rowpercent,0.1);
	if &sdh='3_Never Screened' then 
		nodoc_&sdh=round(rowpercent,0.1);
	if _type_='10' then do;
		total=round(percent,0.1);
			output;
	end;
end;
length Variable $25;
if ever_due=1 then do;
	Variable='Due during observation';
	Row=34;
	if &sdh='1_Positive Screen' then 
		need_&sdh=round(rowpercent,0.1);
	if &sdh='2_Negative Screen' then 
		noneed_&sdh=round(rowpercent,0.1);
	if &sdh='3_Never Screened' then 
		nodoc_&sdh=round(rowpercent,0.1);
	if _type_='10' then do;
		total=round(percent,0.1);
			output;
	end;
end;
run;
data &temp;
set &cancer row33_34;
run;
data chisq_neverdue&sdh;
set chisq_neverdue&sdh;
where statistic='Chi-Square';
length characteristic $15;
characteristic='Never due during obs';
run;
proc sort data=&temp;
by row variable total;
run;
data &out_chi;
set /*chisq_sex&sdh*/
chisq_race&sdh
chisq_language&sdh
chisq_age&sdh
chisq_payer&sdh
chisq_FPL&sdh
chisq_visits&sdh
chisq_obs&sdh
chisq_status&sdh
chisq_neverdue&sdh;
run;
proc datasets library=final details;
quit;